/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: Universidad del Pais Vasco
 * License Type: Academic
 */
package orm;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

public class RecursoDAO {
	public static Recurso loadRecursoByORMID(int id) throws PersistentException {
		try {
			PersistentSession session = orm.BibliotecaPersistentManager.instance().getSession();
			return loadRecursoByORMID(session, id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Recurso getRecursoByORMID(int id) throws PersistentException {
		try {
			PersistentSession session = orm.BibliotecaPersistentManager.instance().getSession();
			return getRecursoByORMID(session, id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Recurso loadRecursoByORMID(int id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.BibliotecaPersistentManager.instance().getSession();
			return loadRecursoByORMID(session, id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Recurso getRecursoByORMID(int id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.BibliotecaPersistentManager.instance().getSession();
			return getRecursoByORMID(session, id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Recurso loadRecursoByORMID(PersistentSession session, int id) throws PersistentException {
		try {
			return (Recurso) session.load(orm.Recurso.class, new Integer(id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Recurso getRecursoByORMID(PersistentSession session, int id) throws PersistentException {
		try {
			return (Recurso) session.get(orm.Recurso.class, new Integer(id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Recurso loadRecursoByORMID(PersistentSession session, int id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Recurso) session.load(orm.Recurso.class, new Integer(id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Recurso getRecursoByORMID(PersistentSession session, int id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Recurso) session.get(orm.Recurso.class, new Integer(id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static List queryRecurso(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.BibliotecaPersistentManager.instance().getSession();
			return queryRecurso(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static List queryRecurso(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.BibliotecaPersistentManager.instance().getSession();
			return queryRecurso(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Recurso[] listRecursoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.BibliotecaPersistentManager.instance().getSession();
			return listRecursoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Recurso[] listRecursoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.BibliotecaPersistentManager.instance().getSession();
			return listRecursoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static List queryRecurso(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Recurso as Recurso");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.list();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static List queryRecurso(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Recurso as Recurso");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.list();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Recurso[] listRecursoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		try {
			List list = queryRecurso(session, condition, orderBy);
			return (Recurso[]) list.toArray(new Recurso[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Recurso[] listRecursoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			List list = queryRecurso(session, condition, orderBy, lockMode);
			return (Recurso[]) list.toArray(new Recurso[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Recurso loadRecursoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.BibliotecaPersistentManager.instance().getSession();
			return loadRecursoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Recurso loadRecursoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.BibliotecaPersistentManager.instance().getSession();
			return loadRecursoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Recurso loadRecursoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Recurso[] recursos = listRecursoByQuery(session, condition, orderBy);
		if (recursos != null && recursos.length > 0)
			return recursos[0];
		else
			return null;
	}
	
	public static Recurso loadRecursoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Recurso[] recursos = listRecursoByQuery(session, condition, orderBy, lockMode);
		if (recursos != null && recursos.length > 0)
			return recursos[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateRecursoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.BibliotecaPersistentManager.instance().getSession();
			return iterateRecursoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateRecursoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.BibliotecaPersistentManager.instance().getSession();
			return iterateRecursoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateRecursoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Recurso as Recurso");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateRecursoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Recurso as Recurso");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Recurso createRecurso() {
		return new orm.Recurso();
	}
	
	public static boolean save(orm.Recurso recurso) throws PersistentException {
		try {
			orm.BibliotecaPersistentManager.instance().saveObject(recurso);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean delete(orm.Recurso recurso) throws PersistentException {
		try {
			orm.BibliotecaPersistentManager.instance().deleteObject(recurso);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean refresh(orm.Recurso recurso) throws PersistentException {
		try {
			orm.BibliotecaPersistentManager.instance().getSession().refresh(recurso);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean evict(orm.Recurso recurso) throws PersistentException {
		try {
			orm.BibliotecaPersistentManager.instance().getSession().evict(recurso);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Recurso loadRecursoByCriteria(RecursoCriteria recursoCriteria) {
		Recurso[] recursos = listRecursoByCriteria(recursoCriteria);
		if(recursos == null || recursos.length == 0) {
			return null;
		}
		return recursos[0];
	}
	
	public static Recurso[] listRecursoByCriteria(RecursoCriteria recursoCriteria) {
		return recursoCriteria.listRecurso();
	}
}
